# coding:utf-8
import pandas as pd
from sklearn import *
import numpy as num

num.set_printoptions(suppress=True)


# 数据获取
def getData():
    model= pd.read_csv("G:/学习教程/人工智能/测试数据文件夹/flow_model.csv")
    tree= pd.read_csv("G:/学习教程/人工智能/测试数据文件夹/flow_tree.csv")
    file= pd.read_csv("G:/学习教程/人工智能/测试数据文件夹/flow_work_file.csv")

    model2=model.filter(items=['flow_mode_id','is_latest']).fillna(0)
    tree2=tree.filter(items=['flow_tree_id','flow_mode_id','level','top_id']).fillna(0)
    file2=file.filter(items=['id','flow_tree_id','is_delete']).fillna(0)
    # print(model2.info())
    # print(tree2.info())
    # print(file2.info())
    model_tree=pd.merge(model2,tree2,on=['flow_mode_id','flow_mode_id'])
    model_tree2=pd.merge(model_tree,file2,on=['flow_tree_id','flow_tree_id'])
    # print(model_tree2.head(2))
    return model_tree2

# 数据特征选择
def selectData(data):
    var=feature_selection.VarianceThreshold(threshold= 0.1)   #删除方差小于设置值的特征的数据
    selectData=var.fit_transform(data)
    # print(selectData)
    return selectData
# 数据降维
def proprocessData(data):
    PCA=decomposition.PCA(n_components=0.95)
    pcaData=PCA.fit_transform(data)
    return pcaData

# 特殊的分组方式
def groupBy(data):
    # data=data[1:20]
    # print(data[1:20])
    groupData=pd.crosstab(data['flow_mode_id'],data['id']) #根据flow_mode_id和id的对应关系 进行分组
    # print(groupData)
    return groupData

if __name__ == '__main__' :
    # groupData=groupBy(getData())
    # print(groupData)
    data=getData()
    processData=selectData(data)
    result=proprocessData(processData)
    print(result)

